package converter;

import org.apache.struts2.util.StrutsTypeConverter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

public class DateConverter extends StrutsTypeConverter {
    @Override
    public Object convertFromString(Map map, String[] strings, Class aClass) {
        try {
            Date birthDay = new SimpleDateFormat("yyyy年MM月dd日").parse(strings[0]);
            return birthDay;
        } catch (ParseException e) {
            e.printStackTrace();
            return "moterDate";
        }
    }
    @Override
    public String convertToString(Map map, Object o) {
        Date date = (Date) o;
        return new SimpleDateFormat("yyyy-MM-dd").format(date);
    }
}
